{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "计算变异系数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "def coefficient_of_variation(data):\n",
    "    mean=numpy.mean(data) #计算平均值\n",
    "    std=numpy.std(data,ddof=0) #计算标准差\n",
    "    cv=std/mean\n",
    "    return cv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CV_1 0.5\n",
      "CV_2 0.6943650748294136\n"
     ]
    }
   ],
   "source": [
    "data_test_1=[1,2,3,4,5,6,7]\n",
    "data_test_2=[1,1,1,4,7,7,7]\n",
    "print('CV_1',coefficient_of_variation(data_test_1))\n",
    "print('CV_2',coefficient_of_variation(data_test_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
